package p.ithorns.framework.web.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * RequestHeaderContextInterceptor
 *
 * @author Ht.L
 * @date 2023-05-26 18:27
 * @since 1.0.0
 */
public class RequestHeaderContextInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        initHeaderContext(request);
        return true;
    }

    private void initHeaderContext(HttpServletRequest request) {
        RequestHeaderContext.build(request);
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
        RequestHeaderContext.clean();
    }

}